<?php 
if(!preg_match("/localhost/", $_SERVER['HTTP_REFERER'])) {
   echo "<script language=\"javascript\">location.href='index.php';</script>";
   exit;
}
?>